<?php

namespace App\Http\Middleware;

use Closure;
use Route;
use Illuminate\Support\Facades\Auth;

class CheckToken
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $route = Route::currentRouteName();
        $id = Auth::guard("admins")->id();
        if($id != 1 && isset($route)){
            if(!is_permission($id,$route)){
                return redirect()->intended('admin/');
            }
        }
        return $next($request);
    }
}
